home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-27 | 8.3 KB | 317 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UMacsBugApplication.cp
- // Copyright © 1991-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- /*
- Change History:
- 6/27/97 TWB QTML headers: Include Sound.h to get SysBeep.
- ----- R11 -----
- 06/26/96 mdr Install release marker. Scope many globals. Change TRUE/FALSE/NULL.
- 06/11/96 gjc Add global scoping for toolbox calls
- 06/01/96 gjc [1327013] kSignature = SS02 - It was using
- the default value (SS01), which conflict with "Nothing".
- See the .r file for more details.
- Added Change history.
- ----- R10 -----
- */
-
- #ifndef __UMACSBUGAPPLICATION__
- #include "UMacsBugApplication.h"
- #endif
-
- #ifndef __MACSBUG_R_H__
- #include "MacsBug.r.h"
- #endif
-
- // MacApp
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- // Toolbox
-
- #ifndef __SOUND__
- #include <Sound.h>
- #endif
-
-
- //========================================================================================
- // GLOBAL Functions
- //========================================================================================
-
- void HeapCheck(TAppleEvent* message, TAppleEvent* reply);
- void HeapTotal(TAppleEvent* message, TAppleEvent* reply);
- void HeapDisplay(TAppleEvent* message, TAppleEvent* reply);
- void SpecifyHeap(TAppleEvent* message, CStr255& command);
- void DoMacsBugCommand(const CStr255& commandString, TAppleEvent* reply);
- void DumpAppleEvent(const AEDescList* message);
-
- //========================================================================================
- // CLASS TMacsBugApplication
- //========================================================================================
- #undef Inherited
- #define Inherited TApplication
-
- #pragma segment AInit
- MA_DEFINE_CLASS_M1(TMacsBugApplication, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TMacsBugApplication constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TMacsBugApplication::TMacsBugApplication()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TMacsBugApplication destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TMacsBugApplication::~TMacsBugApplication()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TMacsBugApplication::IMacsBugApplication:
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
-
- void TMacsBugApplication::IMacsBugApplication()
- {
- IApplication(kFileType, kSignature);
-
- fLaunchWithNewDocument = false;
- }
-
- //----------------------------------------------------------------------------------------
- // TMacsBugApplication::DoScriptCommand
- //----------------------------------------------------------------------------------------
-
- void TMacsBugApplication::DoScriptCommand(CommandNumber aCommand, TAppleEvent* message,
- TAppleEvent* reply)
- {
- switch (aCommand)
- {
- case cHeapCheck:
- HeapCheck(message, reply);
- break;
-
- case cHeapZones:
- DoMacsBugCommand("\phz", reply);
- break;
-
- case cHeapTotal:
- HeapTotal(message, reply);
- break;
-
- case cHeapDisplay:
- HeapDisplay(message, reply);
- break;
-
- default:
- Inherited::DoScriptCommand(aCommand, message, reply);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // HeapCheck
- //----------------------------------------------------------------------------------------
-
- void HeapCheck(TAppleEvent* message, TAppleEvent* reply)
- {
- CStr255 command;
- command.Empty();
-
- SpecifyHeap(message, command);
-
- command += "hc";
-
- DoMacsBugCommand(command, reply);
- }
-
- //----------------------------------------------------------------------------------------
- // HeapTotal
- //----------------------------------------------------------------------------------------
-
- void HeapTotal(TAppleEvent* message, TAppleEvent* reply)
- {
- CStr255 command;
- command.Empty();
-
- SpecifyHeap(message, command);
-
- command += "ht";
-
- DoMacsBugCommand(command, reply);
- }
-
- //----------------------------------------------------------------------------------------
- // HeapDisplay
- //----------------------------------------------------------------------------------------
-
- void HeapDisplay(TAppleEvent* message, TAppleEvent* reply)
- {
- CStr255 command;
- command.Empty();
-
- SpecifyHeap(message, command);
-
- command += "hd";
-
- DoMacsBugCommand(command, reply);
- }
-
- //----------------------------------------------------------------------------------------
- // SpecifyHeap
- //----------------------------------------------------------------------------------------
-
- void SpecifyHeap(TAppleEvent* message, CStr255& command)
- {
- #if qDebug
- static Boolean pDumpMessage;
- if (pDumpMessage)
- DumpAppleEvent(message);
- #endif
-
- if (message->HasParameter(keyAEMacsBugZone))
- {
- DescType zoneParamType = message->ParameterType(keyAEMacsBugZone);
- if (zoneParamType == typeEnumerated)
- {
- DescType zoneParam = message->ReadEnum(keyAEMacsBugZone);
- if (zoneParam == kAEMacsBugZoneSystem)
- command += "hx SysZone^;";
- else if (zoneParam == kAEMacsBugZoneApplication)
- command += "hx TheZone^;";
- else if (zoneParam == kAEMacsBugZoneUser)
- {
- }
- }
- else
- {
- CStr255 zone;
- message->ReadString(keyAEMacsBugZone, zone);
- command = "hx #";
- command += zone;
- command += ';';
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // DoMacsBugCommand
- //----------------------------------------------------------------------------------------
-
- void DoMacsBugCommand(const CStr255& commandString, TAppleEvent* reply)
- {
- TFile* logFile = NULL;
- Handle responseHandle = NULL;
-
- TRY
- {
- CFSSpec logSpec;
- logSpec.vRefNum = 0;
- logSpec.parID = 0;
- CStr63("\pMacsBug.log.temp").CopyTo(logSpec.name);
-
- logFile = NewFile('TEXT', 'MPS ', kUsesDataFork, noResourceFork, kDataOpen, !kRsrcOpen);
- logFile->Specify(logSpec);
- CStr255 logPath;
- FailOSErr(logFile->GetPathName(logPath));
- logPath += CStr63(logSpec.name);
-
- CStr255 macsBugString = "\p;set suspendprompt;log \"";
- macsBugString += logPath;
- macsBugString += CStr15("\p\";");
- macsBugString += commandString + ";log;g";
- DebugStr(macsBugString);
-
- FailOSErr(logFile->OpenFile());
- Size responseLength;
- FailOSErr(logFile->GetDataLength(responseLength));
- FailOSErr(logFile->SetDataMark(0, fsFromStart));
-
- responseHandle = NewPermHandleClear(responseLength);
- FailNIL(responseHandle);
-
- HLock(responseHandle);
-
- FailOSErr(logFile->ReadData(*responseHandle, responseLength));
- FailOSErr(logFile->CloseFile());
-
- responseLength -= 14;
-
- if (responseLength > 0)
- reply->WriteParameterPtr(keyDirectObject, typeChar, *responseHandle, responseLength);
-
- HUnlock(responseHandle);
-
- responseHandle = DisposeIfHandle(responseHandle);
-
- FailOSErr(logFile->DeleteFile());
- delete logFile; logFile = NULL;
- }
- CATCH_ALL
- {
- responseHandle = DisposeIfHandle(responseHandle);
- delete logFile; logFile = NULL;
- }
- ENDTRY
- }
-
- //----------------------------------------------------------------------------------------
- // DumpAppleEvent
- //----------------------------------------------------------------------------------------
-
- void DumpAppleEvent(const AEDescList* message)
- {
- fprintf(stderr, "Dumping message\n");
-
- long count;
- FailOSErr(AECountItems(message, &count));
-
- fprintf(stderr, "count = %d\n", count);
-
- //fprintf(stderr, "<pre><tt>\n");
-
- for (long index = 1; index <= count; index++)
- {
- fprintf(stderr, "%3d)", index);
-
- AEKeyword key;
- DescType typeCode;
- Size actualSize;
- OSErr err = AEGetNthPtr(message, index, typeWildCard, &key, &typeCode, NULL, 0, &actualSize);
- if (!err)
- {
- fprintf(stderr, " %.4s %.4s %6d", (char*)&key, (char*)&typeCode, actualSize);
-
- char text[256];
- err = AEGetNthPtr(message, index, typeChar, &key, &typeCode, text, 255, &actualSize);
- if (!err)
- {
- text[actualSize] = 0;
- fprintf(stderr, " %s", text);
- }
- }
-
- if (err != noErr)
- fprintf(stderr, " error %d", err);
-
- fprintf(stderr, "\n");
- }
-
- //fprintf(stderr, "</tt></pre>\n");
- //fprintf(stderr, "<br>\n");
- }
-
- //----------------------------------------------------------------------------------------
- // End of UMacsBugApplication.cp
-
- #pragma segment Inline
-